package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.CountMapper;
import com.tanhua.model.db.Count;
import com.tanhua.model.dto.OptionDto;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class CountApiImpl implements CountApi{
    @Autowired
    private CountMapper countMapper;
    @Override
    public List<Count> findByQuestionId(Integer questionId) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("question_id",questionId);
        return countMapper.selectList(qw);
    }

    @Override
    public Integer findScoreById(OptionDto optionDto) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("question_id",optionDto.getQuestionId());
        qw.eq("count_id",optionDto.getOptionId());
        Count count = countMapper.selectOne(qw);
        return count.getCountScore();
    }
}
